package com.ruoyi.project.newhope.device.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.newhope.device.domain.NewHopeInfraredDevice;
import com.ruoyi.project.newhope.device.service.INewHopeInfraredDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 近红外设备Controller
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/api/newhope/device")
public class NewHopeInfraredDeviceController extends BaseController
{

    @Autowired
    private INewHopeInfraredDeviceService newHopeInfraredDeviceService;

    /**
     * 查询近红外设备列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewHopeInfraredDevice newHopeInfraredDevice)
    {
        startPage();
        newHopeInfraredDevice.setValid(1);
        List<NewHopeInfraredDevice> list = newHopeInfraredDeviceService.selectNewHopeInfraredDeviceList(newHopeInfraredDevice);
        return getDataTable(list);
    }

    /**
     * 查询近红外设备列表
     */
    @GetMapping("/getAll")
    @ResponseBody
    public AjaxResult getAll(NewHopeInfraredDevice newHopeInfraredDevice)
    {
        List<NewHopeInfraredDevice> list = newHopeInfraredDeviceService.selectNewHopeInfraredDeviceList(newHopeInfraredDevice);
        return AjaxResult.success(list);
    }

    /**
     * 新增保存近红外设备
     */
    @Log(title = "近红外设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody NewHopeInfraredDevice newHopeInfraredDevice)
    {
        return toAjax(newHopeInfraredDeviceService.insertNewHopeInfraredDevice(newHopeInfraredDevice));
    }

    /**
     * 修改近红外设备
     */
    @GetMapping("/edit/{id}")
    @ResponseBody
    public NewHopeInfraredDevice edit(@PathVariable("id") Long id)
    {
        NewHopeInfraredDevice newHopeInfraredDevice = newHopeInfraredDeviceService.selectNewHopeInfraredDeviceById(id);
        return newHopeInfraredDevice;
    }

    /**
     * 修改保存近红外设备
     */
    @Log(title = "近红外设备", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody  NewHopeInfraredDevice newHopeInfraredDevice)
    {
        return toAjax(newHopeInfraredDeviceService.updateNewHopeInfraredDevice(newHopeInfraredDevice));
    }

    /**
     * 删除近红外设备
     */
    @Log(title = "近红外设备", businessType = BusinessType.DELETE)
    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        return toAjax(newHopeInfraredDeviceService.deleteNewHopeInfraredDeviceByIds(id));
    }
}
